# Copyright 2023 Ant Group Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

proto_library(
    name = "mock_report_service_proto",
    srcs = ["mock_report_service.proto"],
    deps = [
        "//api:engine_proto",
    ],
)

proto_library(
    name = "error_collector_service_proto",
    srcs = ["error_collector_service.proto"],
    deps = [
        "//api:engine_proto",
        "//api:status_proto",
    ],
)

proto_library(
    name = "prometheus_service_proto",
    srcs = ["prometheus_service.proto"],
)

cc_proto_library(
    name = "mock_report_service_cc_proto",
    deps = [":mock_report_service_proto"],
)

cc_proto_library(
    name = "error_collector_service_cc_proto",
    deps = [":error_collector_service_proto"],
)

cc_proto_library(
    name = "prometheus_service_cc_proto",
    deps = [":prometheus_service_proto"],
)

cc_library(
    name = "error_collector_service_impl",
    srcs = ["error_collector_service_impl.cc"],
    hdrs = ["error_collector_service_impl.h"],
    visibility = ["//engine/exe:__pkg__"],
    deps = [
        ":error_collector_service_cc_proto",
        "//api:engine_cc_proto",
        "//api:status_cc_proto",
        "//engine/framework:session_manager",
        "@com_github_brpc_brpc//:brpc",
    ],
)

cc_library(
    name = "prometheus_service_impl",
    srcs = ["prometheus_service_impl.cc"],
    hdrs = ["prometheus_service_impl.h"],
    visibility = ["//engine/exe:__pkg__"],
    deps = [
        ":prometheus_service_cc_proto",
        "//api:status_cc_proto",
        "//engine/util:prometheus_monitor",
        "@com_github_brpc_brpc//:brpc",
        "@com_github_brpc_brpc//:butil",
        "@yacl//yacl/base:exception",
    ],
)

cc_library(
    name = "engine_service_impl",
    srcs = ["engine_service_impl.cc"],
    hdrs = ["engine_service_impl.h"],
    visibility = ["//engine/exe:__pkg__"],
    deps = [
        ":error_collector_service_impl",
        ":pipeline",
        "//api:common_cc_proto",
        "//api:engine_cc_proto",
        "//api:status_cc_proto",
        "//engine/audit:audit_log",
        "//engine/auth:authenticator",
        "//engine/datasource:datasource_adaptor_mgr",
        "//engine/datasource:embed_router",
        "//engine/framework:exec",
        "//engine/framework:executor",
        "//engine/framework:session_manager",
        "//engine/link:channel_manager",
        "//engine/link:mux_link_factory",
        "//engine/link:mux_receiver_service",
        "//engine/operator:all_ops_register",
        "@psi//psi/utils:sync",
    ],
)

cc_test(
    name = "engine_service_impl_test",
    srcs = ["engine_service_impl_test.cc"],
    deps = [
        ":engine_service_impl",
        ":mock_report_service_cc_proto",
        "//engine/operator:test_util",
        "@com_google_googletest//:gtest_main",
        "@org_pocoproject_poco//:poco",
    ],
)

cc_library(
    name = "pipeline",
    srcs = ["pipeline.cc"],
    hdrs = ["pipeline.h"],
    visibility = ["//engine/exe:__pkg__"],
    deps = [
        "//api:engine_cc_proto",
        "//engine/core:tensor",
        "//engine/core:tensor_constructor",
        "//engine/framework:session",
        "//engine/util:filepath_helper",
        "@org_apache_arrow//:arrow",
    ],
)
